Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Babel config #31011

Merged
merged 1 commit into from
Jun 25, 2020
Merged

Update Babel config #31011

merged 1 commit into from
Jun 25, 2020

Conversation

XhmikosR
Copy link
Member

@XhmikosR XhmikosR commented Jun 11, 2020

  • remove plugin-proposal-object-rest-spread
  • add bugfixes
  • exclude: ['transform-typeof-symbol'] did nothing with our config

Closes #31007

@XhmikosR
Copy link
Member Author

@hzoo just so we are safe, LGTY? :)

.babelrc.js Outdated
@@ -4,12 +4,11 @@ module.exports = {
'@babel/preset-env',
{
loose: true,
modules: false,
exclude: ['transform-typeof-symbol']
modules: false
}
]
],
plugins: [
'@babel/plugin-proposal-object-rest-spread'
Copy link
Contributor

@hzoo hzoo Jun 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah if you want equivalent behavior sure! I just was confused why you're still defining the plugin here since you removed it from the deps but I guess you are relying on preset-env to have the dep.. but after reading the issue, see loose removes the typeof-symbol plugin so it's not needed, and object-rest-spread is included.. However you can't pass every option down to each plugin specifically (only loose in this case).

Apologies Babel is still so confusing! The difference in output is due to how plugins/presets are working so here's a long explanation. Plugins run before presets so in this case, it's running the object rest spread plugin without loose so it uses the _objectSpread helper function. loose makes it use the _extends helper which is an alias for Object.assign. And there's even another option useBuiltIns which simply replaces it for Object.assign if you can assume that it's polyfilled or supported.

My recommendation is to use loose with object-rest-spread. Is there a reason you don't want "babel is extending Object.assign."? It would save more space due to less helpers being needed as you probably don't use it in a way that requires that spec behavior.

Example from CodeSandbox I made for comparing configs:

Screen Shot 2020-06-13 at 3 09 02 AM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hzoo TBH I was just trying to make sure we do things the right way because we haven't touched this stuff for a long time :)

Is there a reason you don't want "babel is extending Object.assign."?

I thought it would make more sense to go with the official way and not the Object.assign way. Other than that I'm not aware of any other reason. Do note that I didn't originally set this up myself.

So, I'm open to suggestions how to make things the right way. If you think it makes sense to keep the plugin listed in devDependencies, I can revert that part. I'm in between myself since I prefer to list everything I need directly. On the other hand, I didn't even know that this was included in preset-env until I played with it.

Thanks for the reply!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we haven't touched this stuff for a long time :)
I thought it would make more sense to go with the official way and not the Object.assign way

Totally understandable! I don't think the way people use Babel is thinking about it all the time, it's interesting figuring out how to correlate perf/size/convenience/spec.

Looking at https://unpkg.com/browse/bootstrap@4.5.0/dist/js/bootstrap.js, it includes _objectSpread2, ownKeys, _defineProperty because of the spec version of object rest spread (which is fine) but looking at usage you aren't doing anything like using defineProperties (writeable/enumerable) or using getters/setters so the Object.assign version should be fine. But if we want to make sure it behaves the same that can be another test (or unit test would cover it?).

config = {
  ...Default,
  ...config
}

If you think it makes sense to keep the plugin listed in devDependencies
This is more about how npm works (if it's not directly there it uses the one from somewhere else, so either should be ok.

Also another thing is that if you are dropping IE, you can change the output via babel using targets but i'll write more in a bit

Copy link
Contributor

@hzoo hzoo Jun 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yeah my recommendation is to do (blog for more context on bugfixes but it should be default in next major):

module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        loose: true,
		bugfixes: true,
        modules: false,
      }
    ]
  ]
}

so I would remove that plugin reference of plugins: ['@babel/plugin-proposal-object-rest-spread'] since it's fine to rely on the loose behavior in these simple cases?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was checking out https://blog.getbootstrap.com/2020/06/16/bootstrap-5-alpha/ and I was looking at https://github.com/twbs/bootstrap/blob/main/.browserslistrc, and after some rabbit hole.. it seems like maybe Babel has a bug with parsing Android >= 6 for some reason.. but it looks like Android >= 5 (compat-table/compat-table#801) uses Chrome on Android instead of android webview.

image

So looks like after 4.4.4, there are no more versions and it just matches mobile android (which follows Chrome's versioning)? So I would suggest changing the value to android 81 or using ChromeAndroid or and_chr for Chrome for Android instead.

This way Babel wouldn't run as many plugins and it would save a lot of bytes since IE is dropped

Copy link
Member Author

@XhmikosR XhmikosR Jun 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply @hzoo!

I just spent a few hours today due to this :/

I will probably make a new issue because I can't figure this out. Basically, the moment I remove Android our BrowserStack tests fail on Edge.

https://github.com/twbs/bootstrap/pull/30986/commits

IIRC the behavior is normal because after Android 6 (?) Android WebView is using Chrome behind the scenes. What I don't get is why babel doesn't transform the other things so that they still work on Edge. But maybe we are missing something else in our test configuration.

Back to this PR, if you could PR against main what you think is the best that would be perfect :) Ideally, we should backport any cleanup on v4-dev too so that there isn't a big diff between the two branches, apart from the browsers we support.

Thanks for the help!

EDIT: another issue I hit was that Edge >= 16.16299 doesn't include Edge 16 for some reason. So currently on main, browserslist targets Edge 17

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that's very weird.. Android 6 shouldn't represent anything based on my research and Edge 16 is a relatively new version with support for es modules at least on the javascript side so it must be failing because of something else.. and it's odd Android somehow makes Edge/Mobile Safari fail (https://github.com/twbs/bootstrap/runs/788403787?check_suite_focus=true) when both of those are already defined in the browserslist.. with TypeError: Function expected, yeah would need to look into why

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead with your suggestion, although I'd prefer it if you were the patch author :)

It does save us a few bytes from the dist files, not sure if our unit tests cover the Object spread cases. @Johann-S might have a better idea about it.

This tackles the issue on main, for v4-dev I'd need to backport it and see if everything works well.

About the Android issue, I'll make a new issue here to track it, and I already have a draft PR where I experiment with modernizing our browserslist config in #30986, but I hit the aforementioned issue, so I put back Android. Also I split some changes to #31124. Chrome Android is/was already included due to last 1 major version:

C:\Users\xmr\Desktop\bootstrap>npx autoprefixer --info
Browsers:
  Chrome for Android: 81
  Firefox for Android: 68
  And_qq: 10.4
  UC for Android: 12.12
  Android: 81
  Baidu: 7.12
  Chrome: 83, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60
  Edge: 83, 81, 80, 79, 18, 17
  Firefox: 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60
  iOS: 13.4-13.5, 13.3, 13.2, 13.0-13.1, 12.2-12.4, 12.0-12.1, 11.3-11.4, 11.0-11.2, 10.3, 10.0-10.2
  Kaios: 2.5
  Opera Mini: all
  Opera Mobile: 46
  Opera: 68
  Safari: 13.1, 13, 12.1, 12, 11.1, 11, 10.1, 10
  Samsung: 11.1-11.2

Copy link
Contributor

@hzoo hzoo Jun 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool this looks good and should be compatible with v4 to backport.

The only breaking change would be modifying the browserslist (dropping IE, but I would try changing Android 6 to Android 81, the difference might be an issue with Babel parsing the browserslist but that should be the right workaround), dropping IE should save a lot more bytes (ex: class A {}).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, for v5 we have dropped IE. I still want to get the Android issue sorted so I'll make an issue for that.

v4 still supports IE so that doesn't apply there :)

@mdo mdo changed the base branch from master to main June 16, 2020 19:31
@XhmikosR XhmikosR force-pushed the master-xmr-babel branch 2 times, most recently from d57a6c6 to b11a493 Compare June 23, 2020 12:35
@XhmikosR XhmikosR requested a review from Johann-S June 23, 2020 12:36
@XhmikosR XhmikosR changed the title Clean up .babelrc.js and remove `@babel/plugin-proposal-object-rest-s… Update Babel config Jun 24, 2020
* remove plugin-proposal-object-rest-spread
* add bugfixes
* `exclude: ['transform-typeof-symbol']` did nothing with our config
@XhmikosR XhmikosR merged commit 22f3241 into main Jun 25, 2020
@XhmikosR XhmikosR deleted the master-xmr-babel branch June 25, 2020 15:38
XhmikosR added a commit that referenced this pull request Jun 30, 2020
* remove plugin-proposal-object-rest-spread
* add bugfixes
* `exclude: ['transform-typeof-symbol']` did nothing with our config
XhmikosR added a commit that referenced this pull request Jul 1, 2020
* remove plugin-proposal-object-rest-spread
* add bugfixes
* `exclude: ['transform-typeof-symbol']` did nothing with our config
XhmikosR added a commit that referenced this pull request Jul 6, 2020
* remove plugin-proposal-object-rest-spread
* add bugfixes
* `exclude: ['transform-typeof-symbol']` did nothing with our config
dsynr added a commit to dsynr/bootstrap that referenced this pull request Aug 21, 2020
* Remove backdrop-filter from toasts

* BrowserStack: test on Edge 15

* Backport twbs#31135

* Move color utility callouts to start of page

Hierarchically/structurally, in the position they are currently at, the two callouts seem like they "belong" just to the "background color" section. Moving them to the start makes it clearer that those two callouts relate to everything in the page (both "Color" and "Background color" classes.

* Change heading level

otherwise the assistive technology callout looks like it's hierarchically under the "Dealing with specificity" heading

* Backport twbs#30326

Prevent overflowing static backdrop modal animation

TODO: backport the test too

* Backport twbs#30326 (Unit test)

* Update Babel config (twbs#31011)

* remove plugin-proposal-object-rest-spread
* add bugfixes
* `exclude: ['transform-typeof-symbol']` did nothing with our config

* Update devDependencies and gems

* Update dependencies, gems and regenerate package-lock.json (twbs#31261)

* @rollup/plugin-node-resolve 8.1.0
* popper.js 1.16.1
* qunit 2.10.1
* rollup 2.21.0

* Docs: forms accessibility cleanup (backport from v5) (twbs#31234)

* Expand advice for anchor-based controls

* Expand accessibility note in input group

* Correct statement about validation, fix server example

* Tweak label > accessible name

Co-authored-by: XhmikosR <xhmikosr@gmail.com>
Co-authored-by: Mark Otto <markd.otto@gmail.com>

* Turn off scroll anchoring for accordions (twbs#31347)

New default behavior for scroll anchoring (rolled out in Chrome 84?) leads to unsightly/odd accordion interactions - see twbs#31341
This rule suppresses this new behavior and reverts back to the old way.

See https://drafts.csswg.org/css-scroll-anchoring/

* Update to Ruby 2.7/Bundler 2.x. (twbs#31296)

* Clear timeout before showing the toast (twbs#31155)

* clear timeout before showing the toast

* Add unit test

* Remove the check for timeout

* Check for clearTimeout to have been called

Co-authored-by: XhmikosR <xhmikosr@gmail.com>
# Conflicts:
#	js/tests/unit/toast.spec.js

* Add unit test for toast to check clearTimeout to have been called (twbs#31298)

* docs(skippy): prevent skip links from overlapping header

* Backport twbs#31344

Add toasts to the components requiring JavaScript

* Update devDependencies and gems

* @babel/cli                   ^7.10.4  →  ^7.11.0
* @babel/core                  ^7.10.4  →  ^7.11.0
* @rollup/plugin-babel          ^5.0.4  →   ^5.1.0
* @rollup/plugin-commonjs      ^13.0.0  →  ^14.0.0
* @rollup/plugin-node-resolve   ^8.1.0  →   ^8.4.0
* autoprefixer                  ^9.8.4  →   ^9.8.6
* eslint                        ^7.4.0  →   ^7.6.0
* karma                         ^5.1.0  →   ^5.1.1
* rollup                       ^2.21.0  →  ^2.23.0

* Remove overflow: hidden from toasts (twbs#31381) (twbs#31407)

Co-authored-by: Mark Otto <markd.otto@gmail.com>

* Backport twbs#31339 (twbs#31414)

* Backport twbs#31339

Add view on GitHub links for easier content editing from the docs

* Prepare v4.5.1. (twbs#31408)

* Remove flex: 1 0 100% from rows (twbs#31439) (twbs#31445)

Co-authored-by: XhmikosR <xhmikosr@gmail.com>

Co-authored-by: Mark Otto <markd.otto@gmail.com>

* Restore make-container-max-widths mixin

* Deprecate the `make-container-max-widths` mixin

* Remove undefined `$ignore-warning`

* Prepare v4.5.2. (twbs#31444)

Co-authored-by: Mark Otto <markd.otto@gmail.com>
Co-authored-by: XhmikosR <xhmikosr@gmail.com>
Co-authored-by: ysds <ysds.code@gmail.com>
Co-authored-by: Patrick H. Lauke <redux@splintered.co.uk>
Co-authored-by: Rohit Sharma <rohit2sharma95@gmail.com>
Co-authored-by: Gaël Poupard <gael.poupard@orange.com>
Co-authored-by: Martijn Cuppens <martijn.cuppens@gmail.com>
olsza pushed a commit to olsza/bootstrap that referenced this pull request Oct 3, 2020
* remove plugin-proposal-object-rest-spread
* add bugfixes
* `exclude: ['transform-typeof-symbol']` did nothing with our config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Revisit .babelrc.js
4 participants